package test3;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class test {
    public static List<String> convertStringToList(String line){
        List ls=new ArrayList<>();
        Scanner sc=new Scanner(line);
        while(sc.hasNext()){
            ls.add(sc.next());
        }
        return ls;
    }

    public static void remove(List<String> list, String str){
        /*Scanner sc=new Scanner(str);
        while(sc.hasNext()){
            if(list.contains(str))
                list.remove(str);
            else
                break;
        }*/
        for(int i=0;i<list.size();i++){
            if(str.compareTo(list.get(i))==0){
                list.remove(i);
                i--;
            }
        }
    }





    public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            while(sc.hasNextLine()){
                List<String> list = convertStringToList(sc.nextLine());
                System.out.println(list);
                String word = sc.nextLine();
                remove(list,word);
                System.out.println(list);
            }
            sc.close();
        }

    }
